package com.system.web;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

//import com.alibaba.fastjson.JSONObject;
//import  com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
//import cn.gson.oasys.model.entity.user.User;

@Controller
//@RequestMapping("/")
public class IndexHTController {

	Logger log = LoggerFactory.getLogger(getClass());

	@RequestMapping(value = "/ERROR")
	public String toError() {
		log.debug("------跳转到错误提示页/common/error.jsp------");
		return "common/error";
	}

	@RequestMapping(value = "/RESETCACHE")
	public String toResetCache() {
		log.debug("------跳转到错误提示页/common/resetCache.jsp------");
		return "common/resetCache";
	}

	@RequestMapping(value = "/ONLINEUSERLIST")
	public String toOnlineUserList() {
		log.debug("------跳转到错误提示页/common/onLineUserList.jsp------");
		return "common/onLineUserList";
	}

	@RequestMapping("/toIndex1")
	public String toIndexPortal(HttpServletRequest req,Model model) {
		log.error("------请求index/index1首页------");
		return "index/index1";
	}

	@RequestMapping("/toIndex2")
	public String toAdmin(HttpServletRequest req,Model model) {
		log.error("------请求index/index2首页------");
		return "index/index2";
	}
	@RequestMapping("/toIndexWY")
	public String toIndexWY(HttpServletRequest req,Model model) {
		log.error("------请求index/indexWY 首页------");
		return "index/indexWY";
	}
	@RequestMapping("/toIndex3")
	public String toFrame(HttpServletRequest req,Model model) {
		log.error("------请求index/index3首页------");
		return "index/toIndex3";
	}

	@RequestMapping("/toPortal2")
	public String toPortal2(HttpServletRequest req,Model model) {
		log.error("------请求indexPortal2首页------");
		return "index/indexPortal2";
	}

	@RequestMapping("/toPortal3")
	public String toPortal3(HttpServletRequest req,Model model) {
		log.error("------请求indexPortal3首页------");
		return "index/indexPortal3";
	}

	//*******************************left导航start**********************************
	//-------------------------------system manager ---------------------------------------------
	@RequestMapping(value = "/system/user")
	public String user() {
		log.debug("------跳转到user------");
		return "system/t_user_detailList";
	}
	@RequestMapping(value = "/system/role")
	public String role() {
		log.debug("------跳转到role------");
		return "system/t_roleList";
	}
	@RequestMapping(value = "/system/function")
	public String function() {
		log.debug("------跳转到function------");
		return "system/t_functionList";
	}

	//*******************************left导航end*************************************
	@RequestMapping("ranhengFrameWY")
	public String ranhengFrameWY(HttpSession session, Model model, HttpServletRequest request) {
		return "index/mainWY";
	}
	/**
	 * 控制面板主页
	 * <iframe src="ranhengFrame" ...></iframe> src会直接请求到该页面；
	 * @param session
	 * @param model
	 * @return
	 */
	@RequestMapping("ranhengFrame")
	public String ranhengFrame(HttpSession session, Model model, HttpServletRequest request) {
		/*
		//列举便签
		List<Notepaper> notepapers=notepaperDao.findByUserIdOrderByCreateTimeDesc(userId);
		model.addAttribute("notepaperList", notepapers);

		//列举几个流程记录
		List<ProcessList> pList=processListDao.findlastthree(userId);
		model.addAttribute("processlist", pList);
		List<SystemStatusList> processstatus = (List<SystemStatusList>) statusDao.findByStatusModel("aoa_process_list");
		model.addAttribute("prostatuslist", processstatus);*/
		return "index/main";
	}

	@RequestMapping("/top")
	public String toTop(HttpServletRequest req,Model model) {
		log.error("------请求首页top------");
		return "index/top";
	}

	@RequestMapping("left")
	public String leftlists(HttpSession session, Model model,HttpServletRequest req){
		log.error("------请求首页leftlists------");
		return "index/left";
	}

	/*
	@RequestMapping("leftlist")
	public String left(HttpSession session, Model model,HttpServletRequest req){
		log.error("------请求首页left------");
		return "common/leftlist";
	}
	 */

	/**
	 * 菜单查找
	@RequestMapping("menucha")
	public String menucha(HttpSession session, Model model,HttpServletRequest req){
		return "common/leftlists";
	}
	 */
	
	/*
	 * 显示首页主页的登录 统计数据
	 * //显示本周的每天的记录
	@RequestMapping("countweeklogin")
	public String dfsa(HttpServletResponse response) throws IOException{
		Integer []r=new Integer[7];
		Calendar calendar=Calendar.getInstance();
		setToFirstDay(calendar);
		for (int i = 0; i < 7; i++) {
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			r[i]= i + 100 ;//userLogRecordDao.countlog(sdf.format(calendar.getTime()));
			if(r[i]>102) {
				r[i] = r[i] -6 ;
			}
			calendar.add(Calendar.DATE, 1);
		}
		//String json=JSONObject.toJSONString(r);
		Gson gson = new Gson();
		String json = gson.toJson(r);
		//String json = gson.toString();
		System.out.println(json);
		response.setHeader("Cache-Control", "no-cache");
		response.setContentType("text/json;charset=UTF-8");
		response.getWriter().write(json);
		return null;
	}*/
	
	private static void setToFirstDay(Calendar calendar) {
        while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            calendar.add(Calendar.DATE, -1);
        }
    }
	
	//显示任务统计模块数据
	/*
	@RequestMapping("counttasknum")
	public String test3df(HttpServletResponse response) throws IOException {
		ArrayList<Map.Entry<String,Integer>> entries2=new ArrayList<Map.Entry<String,Integer>>();
		HashMap< String, Integer> hashMap=new HashMap<>();
		hashMap.put("张峰", 20);
		hashMap.put("李海", 15);
		hashMap.put("李隆基", 20);
		hashMap.put("石中玉", 25);
		hashMap.put("赵胜", 23);
		
	    Gson gson = new Gson();
		String json = gson.toJson(hashMap);
		System.out.println(json);
		response.setHeader("Cache-Control", "no-cache");
		response.setContentType("text/json;charset=UTF-8");
		response.getWriter().write(json);
		return null;
	}
	*/

}
